import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'
// https://vite.dev/config/

export default defineConfig({
  // ...
  plugins: [
    vue(),
    AutoImport({
      resolvers: [ElementPlusResolver()],
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
  ],
  server:{
    proxy:{
      // 第一个代理
      '/fnji': {
        target: 'https://website.fnji.com',
        changeOrigin: true,
        configure: (proxy, options) => {
          proxy.on("proxyReq", (proxyReq, req, res) => {
            // 在代理请求中添加自定义 header ，伪装本次请求
            // host:website.fnji.com
            // origin:https://www.fnji.com
            // referer:https://www.fnji.com/
            proxyReq.setHeader("host", "website.fnji.com"); //从目标网站找到请求头
            proxyReq.setHeader("origin", "https://www.fnji.com");
            proxyReq.setHeader("Referer", "https://www.fnji.com/");
          });
        },
        rewrite: (path) => path.replace(/^\/fnji/, ''),
      },

      // 第二个代理
      '/dayi': {
        target: 'https://server.dayi.org.cn',
        changeOrigin: true,
        configure: (proxy, options) => {
          proxy.on("proxyReq", (proxyReq, req, res) => {
            // 在代理请求中添加自定义 header ，伪装本次请求
            // proxyReq.setHeader("host", "website.fnji.com"); //从目标网站找到请求头
            proxyReq.setHeader("origin", "https://www.dayi.org.cn/");
            proxyReq.setHeader("Referer", "https://www.dayi.org.cn/");
          });
        },
        rewrite: (path) => path.replace(/^\/dayi/, ''),
      },
      // 第三个代理
      '/tyapi': {
        target: 'https://tyapi.71360.com',
        changeOrigin: true,
        configure: (proxy, options) => {
          proxy.on("proxyReq", (proxyReq, req, res) => {
            proxyReq.setHeader("host", "tyapi.71360.com"); //从目标网站找到请求头
            proxyReq.setHeader("origin", "http://www.ccsinter.com");
            proxyReq.setHeader("Referer", "http://www.ccsinter.com/");
          });
        },
        rewrite: (path) => path.replace(/^\/tyapi/, ''),
      },
    }
  }
})